package com.xul.yygh.common.utils;

import com.xul.yygh.common.helper.JwtHelper;

import javax.servlet.http.HttpServletRequest;

/**
 * 获取当前用户的信息
 *
 * @author xul
 * @create 2021-07-15 17:01
 */
public class AuthContextHolder {

    /**
     * 获取当前用户的用户id
     *
     * @param request
     * @return
     */
    public static Long getUserId(HttpServletRequest request) {
        // 从header获取到token
        String token = request.getHeader("token");
        // jwt中获取userId
        return JwtHelper.getUserId(token);
    }

    public static String getUserName(HttpServletRequest request) {
        String token = request.getHeader("token");
        return JwtHelper.getUserName(token);
    }
}
